<?php
/**
 * GeryEngine
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this release in the file LICENSE
 *
 * @copyright  Copyright (c) 2007 Arjen Brouwer
 * @license    New BSD License
 * @author     Arjen Brouwer
 */

class TemplateMath {
	
	public static function add($a, $b) {
		
		if (is_int($a)) {
			return $a + (int)$b;
		
		} else if (is_string($a)) {
			return $a . (string)$b;
			
		} else if (is_array($a) && is_array($b))	{
			return array_merge($a, $b);
			
		} else {
			return (int)$a + (int)$b;
		}
	}
	
	public static function substract($a, $b) {
		
		if (is_int($a)) 
		{
			return $a - (int)$b;
		} 
		else if (is_string($a)) 
		{
			return str_replace((string)$b, '', $a);
		} else if (is_array($a) && is_array($b)) {
			return array_diff($a, $b);
		} else {
			return (int)$a - (int)$b;
		}
	}
	
	public static function multiply($a, $b) {
		if (is_numeric($a) && is_numeric($b)) {
			return $a * $b;
		} else if (is_numeric($a) && is_string($b) || is_string($a) && is_numeric($b)) {
			if (is_numeric($a)) {
				return str_repeat($b, $a);
			} else {
				return str_repeat($a, $b);
			}
		} else {
			return (double)$a * (double)$b;
		}
	}
	
	public static function divide($a, $b) {
		$b = (int)$b;
		
		if (! $b)
			return 0;
			
		return $a / $b;
	}
	
	public static function modulus($a, $b) {
		return (int)$a % (int)$b;
	}
	
	public static function arrayRange($low, $high) 
	{
		if (! is_int($low) || ! is_int($high)) 
		{
			return null;
		}
		
		return range($low, $high);
	}
}
?>